<?php
 include "connect.php";
 include "functions.php";
 
 $badgedata = $_POST['badge_name'];

 if(empty($badgedata))
  {
    echo("You didn't delete any badges.");
  $url = "delete_saved_badge.php";
 echo '<meta http-equiv="refresh" content="2;URL=' . $url . '">';

  }
  else
  {
    $N = count($badgedata);
    for($i=0; $i < $N; $i++)
    {

    $badgeid = $badgedata[$i] ;
	  
	  $query="SELECT * FROM saved_badge_id WHERE ID='$badgeid'";
      $result = mysqli_query($con, $query) or die("query:" . mysql_error($con));
      $photo = mysqli_result($result,$i,"photo");
	
	$ok1 = mysqli_query($con, "DELETE FROM saved_badge_id WHERE ID='$badgeid'");
	
           if ($ok1) {  
                     echo('<span style="color:green;text-align:center;font-size:12pt;">Badge ID#'.$badgeid.' deleted successfully!</span><br>');
//                   unlink($photo);
                      } 
                     else 
                     {  
                       
					   echo('<p>Error deleting data from database!<br />'.       'Error: ' . mysql_error() . '</p>');
                     }
	}
  }
   $url = "delete_saved_badge.php";
 echo '<meta http-equiv="refresh" content="2;URL=' . $url . '">';
?>

